﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

#nullable disable

namespace Hwh_Shop.Models.Database
{
    public partial class Hwh_ShopContext : DbContext
    {
        public Hwh_ShopContext()
        {
        }

        public Hwh_ShopContext(DbContextOptions<Hwh_ShopContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Commodity> Commodities { get; set; }
        public virtual DbSet<CommodityCategorize> CommodityCategorizes { get; set; }
        public virtual DbSet<Order> Orders { get; set; }
        public virtual DbSet<OrderDetailed> OrderDetaileds { get; set; }
        public virtual DbSet<ShoppingCar> ShoppingCars { get; set; }
        public virtual DbSet<User> Users { get; set; }
        public virtual DbSet<WaybillOfInformation> WaybillOfInformations { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
                optionsBuilder.UseSqlServer("Data Source=.;Initial Catalog=Hwh_Shop;User ID= sa;Password=123456;Integrated Security=SSPI");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("Relational:Collation", "Chinese_PRC_CI_AS");

            modelBuilder.Entity<Commodity>(entity =>
            {
                entity.HasKey(e => e.ComNo)
                    .HasName("PK__Commodit__E15A324192D3BE01");

                entity.ToTable("Commodity");

                entity.Property(e => e.ComCreateTime).HasColumnType("datetime");

                entity.Property(e => e.ComName).IsRequired();

                entity.Property(e => e.ComPhoto)
                    .IsRequired()
                    .HasMaxLength(200);

                entity.Property(e => e.ComPrice).HasColumnType("numeric(18, 2)");

                entity.Property(e => e.ComRefer).IsRequired();
            });

            modelBuilder.Entity<CommodityCategorize>(entity =>
            {
                entity.HasKey(e => e.ComCateNo)
                    .HasName("PK__Commodit__12414DE15C238194");

                entity.ToTable("Commodity_Categorize");

                entity.Property(e => e.ComCateName)
                    .IsRequired()
                    .HasMaxLength(20);
            });

            modelBuilder.Entity<Order>(entity =>
            {
                entity.HasKey(e => e.No)
                    .HasName("PK__Orders__3214D4A83083B65C");

                entity.Property(e => e.OrderNo)
                    .IsRequired()
                    .HasMaxLength(20);

                entity.Property(e => e.OrderPrice).HasColumnType("numeric(18, 2)");

                entity.Property(e => e.OrderState)
                    .IsRequired()
                    .HasMaxLength(5);

                entity.Property(e => e.OrderUser)
                    .IsRequired()
                    .HasMaxLength(11);
            });

            modelBuilder.Entity<OrderDetailed>(entity =>
            {
                entity.HasKey(e => e.No)
                    .HasName("PK__Order_De__3214D4A8AF44DE32");

                entity.ToTable("Order_Detailed");

                entity.Property(e => e.ComName).IsRequired();

                entity.Property(e => e.ComPhoto)
                    .IsRequired()
                    .HasMaxLength(200);

                entity.Property(e => e.ComPrice).HasColumnType("numeric(18, 2)");

                entity.Property(e => e.ComRefer).IsRequired();

                entity.Property(e => e.OrderNo)
                    .IsRequired()
                    .HasMaxLength(20);

                entity.Property(e => e.OrderUser)
                    .IsRequired()
                    .HasMaxLength(11);
            });

            modelBuilder.Entity<ShoppingCar>(entity =>
            {
                entity.HasKey(e => e.ShopCarNo)
                    .HasName("PK__Shopping__9744F4C09385D1C2");

                entity.ToTable("Shopping_Cars");

                entity.Property(e => e.ShopCarUser)
                    .IsRequired()
                    .HasMaxLength(11);
            });

            modelBuilder.Entity<User>(entity =>
            {
                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Createtime)
                    .HasColumnType("datetime")
                    .HasColumnName("createtime");

                entity.Property(e => e.Name)
                    .HasMaxLength(20)
                    .HasColumnName("name");

                entity.Property(e => e.Password)
                    .IsRequired()
                    .HasMaxLength(16)
                    .HasColumnName("password");

                entity.Property(e => e.Photo)
                    .HasMaxLength(200)
                    .HasColumnName("photo");

                entity.Property(e => e.Tel)
                    .IsRequired()
                    .HasMaxLength(11)
                    .HasColumnName("tel");
            });

            modelBuilder.Entity<WaybillOfInformation>(entity =>
            {
                entity.HasKey(e => e.WayInNo)
                    .HasName("PK__WaybillO__1209E0A634DF20C6");

                entity.ToTable("WaybillOfInformation");

                entity.Property(e => e.WayInNo).HasMaxLength(50);

                entity.Property(e => e.OrderNo)
                    .IsRequired()
                    .HasMaxLength(20);

                entity.Property(e => e.WayInFirm)
                    .IsRequired()
                    .HasMaxLength(20);
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
